using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using TienTeTuong;
using log4net;
namespace TienTeTuong
{
    public class CategoryBUS
    {
        
         public List<CategoryDTO> GetListCategory()
         {
             var dao = new CategoryDAO();
             return dao.GetListCategory();
         }
         public string GetCateNameByID(string CateID)
         {
             var dao = new CategoryDAO();
             return dao.GetCateNameByID(CateID);
         }
         public List<CategoryDTO> GetListCategoryByPage(int numPage, out int iTotalPages, out int iCurPage, out int iLowerPage, out int iUpperPage, out int iTotalResult)
         {
                 
                 iCurPage = numPage;
                 var dao = new CategoryDAO();
                 iTotalResult = dao.GetNumCategory();

                 iTotalPages = iTotalResult / Common.iNumItemPerPage + (iTotalResult % Common.iNumItemPerPage > 0 ? 1 : 0);
                 if (iCurPage < 1) iCurPage = 1;
                 if (iCurPage > iTotalPages) iCurPage = iTotalPages;
                 Common.CalculateBoundry(Common.iNumItemPerPage,iTotalPages,iCurPage,out iLowerPage,out iUpperPage);
                 var offsetFirstRow = (iCurPage - 1) * Common.iNumItemPerPage;
                 if (offsetFirstRow < 0) offsetFirstRow = 0;

                 return dao.GetListCategoryByPage(offsetFirstRow,Common.iNumItemPerPage);
             
          }
         public List<CategoryDTO> searchCategoryByName(string key)
         {
             var dao = new CategoryDAO();
             return dao.searchCategoryByName(key);
         }
         public bool delete(string key)
         {
             var dao = new CategoryDAO();
             return dao.delete(key);
         }
         public CategoryDTO GetCateByID(string CateID)
         {
             var dao = new CategoryDAO();
             return dao.GetCateByID(CateID);
         }
         public bool update(CategoryDTO item)
         {
             var dao = new CategoryDAO();
             return dao.update(item);
         }

         public bool add(CategoryDTO item)
         {
             var dao = new CategoryDAO();
             return dao.add(item);
         }
    }
}
